<template>
    测试
</template>
<script setup>
import axios from 'axios'

const getSevevDay = async () => {
    let sevenDay = []
    const res = await axios.get(`https://rmt.gx121.com:8686/api2/v1/external/forecast/7days/108.55,22.78`)
    console.log(res.data);
    const temList = res.data.tem
    const wepList = res.data.wep
    const windGradeList = res.data.windGrade
    const windDirectionList = res.data.windAzimuth
    let pevNum = -2
    let lastNum = 0
    let dayList = ["日", "一", "二", "三", "四", "五", "六"];
    for (let item = 0; item < temList.length / 2; item++) {
        pevNum += 2
        lastNum = pevNum + 1
        let today = new Date();
        let targetday_milliseconds = today.getTime() + 1000 * 60 * 60 * 24 * item;
        today.setTime(targetday_milliseconds);
        let yy = today.getFullYear();
        let mm = today.getMonth() + 1;
        let dd = today.getDate();
        let day = today.getDay()
        if (mm < 10) mm = '0' + mm;
        if (dd < 10) dd = '0' + dd;
        sevenDay.push({
            temMax: temList[pevNum],
            temMin: temList[lastNum],
            wepMax: wepList[pevNum],
            wepMin: wepList[lastNum],
            date: `${yy}-${mm}-${dd}`,
            day: '周' + dayList[day],
            maxVelocity: windVelocity(windGradeList[pevNum]),
            minVelocity: windVelocity(windGradeList[lastNum]),
            maxDirection:convert_wd_readable(windDirectionList[pevNum]),
            minDirection:convert_wd_readable(windDirectionList[lastNum])
        })
    }
    console.log(sevenDay);

}
const windVelocity = (wind) => {
    for (let item = 0; item < weather_grade.length; item++) {
        if (wind >= weather_grade[item].min && wind <= weather_grade[item].max) {
            return weather_grade[item].grade
        }
    }
}
const weather_grade = [
    {
        min: 0,
        max: 0.2,
        name: '无级',
        grade: '0',
        description: '静，烟直上'
    },
    {
        min: 0.3,
        max: 1.5,
        name: '软风',
        grade: '1',
        description: '烟示风向'
    },
    {
        min: 1.6,
        max: 3.3,
        name: '轻风',
        grade: '2',
        description: '感觉有风'
    },
    {
        min: 3.4,
        max: 5.4,
        name: '微风',
        grade: '3',
        description: '旌旗展开'
    },
    {
        min: 5.5,
        max: 7.9,
        name: '和风',
        grade: '4',
        description: '吹起尘土'
    },
    {
        min: 8.0,
        max: 10.7,
        name: '劲风',
        grade: '5',
        description: '小树摇摆'
    },
    {
        min: 10.8,
        max: 13.8,
        name: '强风',
        grade: '6',
        description: '电线有声'
    },
    {
        min: 13.9,
        max: 17.1,
        name: '疾风',
        grade: '7',
        description: '步行困难'
    },
    {
        min: 17.2,
        max: 20.7,
        name: '大风',
        grade: '8',
        description: '折毁树枝'
    },
    {
        min: 20.8,
        max: 24.4,
        name: '烈风',
        grade: '9',
        description: '小损房屋'
    }, {
        min: 24.5,
        max: 28.4,
        name: '狂风',
        grade: '10',
        description: '拔起树木'
    }, {
        min: 28.5,
        max: 32.6,
        name: '暴风',
        grade: '11',
        description: '损毁重大'
    },
    {
        min: 32.7,
        max: 36.9,
        name: '飓风',
        grade: '12',
        description: '摧毁极大'
    },
    {
        min: 37.0,
        max: 41.4,
        name: '飓风',
        grade: '13',
        description: '摧毁极大'
    },
    {
        min: 41.5,
        max: 46.1,
        name: '飓风',
        grade: '14',
        description: '摧毁极大'
    },
    {
        min: 46.2,
        max: 100,
        name: '飓风',
        grade: '15',
        description: '摧毁极大'
    },
]
const convert_wd_readable = (angle) => {
  try {
    if (angle != null && parseFloat(angle) <= 360) {
      let array = ["北", "东北", "东", "东南", "南", "西南", "西", "西北"];
      return array[Math.floor(((parseFloat(angle) + 22.5) % 360) / 45)];
    }
    return '无';
  } catch (error) {
    return '无'
  }
}
onMounted(() => {
    getSevevDay()
})
</script>
<style lang="less"></style>